﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MPBlog.DAL;
using NHibernate.Criterion;

namespace MPBlog.EasyVS
{
    public partial class Statistics : System.Web.UI.Page
    {
        SoftwareUseStatisticsDao dao = new SoftwareUseStatisticsDao();

        protected void Page_Load(object sender, EventArgs e)
        {
            rpt1.DataSource = dao.GetPage(1, 100, "LastUseTime", false, new List<ICriterion> { Restrictions.Eq("SoftwareName", "easyvs") });
            rpt1.DataBind();
        }

        public string GetIntervalTime(DateTime lastUse)
        {
            TimeSpan ts = DateTime.Now - lastUse;
            if (ts.TotalMinutes < 60)
            {
                return Math.Round(ts.TotalMinutes, 1) + " 分钟前";
            }
            else if (ts.TotalMinutes >= 60 && ts.TotalMinutes <= 60 * 24)
            {
                return Math.Round(ts.TotalHours, 1) + " 小时前";
            }
            else
            {
                return Math.Round(ts.TotalDays, 1) + " 天前（ " + lastUse + " ）";
            }

        }
    }
}